import Vue from 'vue'
import VueRouter from 'vue-router'
// import { getLocal } from '@/utils/local'
// import store from '@/store'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: () => import('@/views/login/login.vue')
  },
  {
    path: '/my',
    component: () => import('@/views/my/my.vue'),
    meta: {
      needNavBar: true
    }
  },
  {
    path: '/info',
    component: () => import('@/views/info/info.vue'),
    meta: {
      needLogin: true
    }
  },
  {
    path: '/infoUploader',
    component: () => import('@/views/info/infoUploader.vue'),
    meta: {
      needLogin: true
    }
  },
  {
    path: '/infoName',
    component: () => import('@/views/info/infoName.vue'),
    meta: {
      needLogin: true
    }
  },
  {
    path: '/infoIntroduce',
    component: () => import('@/views/info/infoIntroduce.vue'),
    meta: {
      needLogin: true
    }
  },
  {
    path: '/xz',
    component: () => import('@/views/my/myxiaozhi.vue')
  },
  {
    path: '/index',
    component: () => import('@/views/index/index.vue'),
    meta: {
      needNavBar: true
    }
  },
  {
    path: '/find',
    component: () => import('@/views/find/find.vue'),
    meta: {
      needNavBar: true
    }
  },
  {
    path: '/findResult',
    component: () => import('@/views/find/findResult.vue')
  },
  {
    path: '/details',
    component: () => import('@/views/details/details.vue')
  }
]

const router = new VueRouter({
  routes
})
// 前置守卫
router.beforeEach((to, from, next) => {
  const _scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  from.meta.scrollTop = _scrollTop
  next()
})
// 后置守卫
router.afterEach((to, from) => {
  window.scrollTo(0, 0)
})

export default router
